package com.IR.user.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.IR.shop.po.Site;

import com.IR.user.service.ASiteBIZ;
/**
 * @author 单立鑫
 * @date 2018-09-07
 * */

@Controller
public class ASiteAction {
	
	@Resource
	private ASiteBIZ biz;
	
	//修改为默认地址，同时把原来默认地址修改为普通地址
	@RequestMapping(value="updateUserSiteScode.do")
	public void updateUserSiteScode(Site site,Long userid) {
		biz.updateSiteScode0(userid);
		biz.updateSiteScode1(site, userid);
		
	}
	
	//修改地址
	@RequestMapping(value="updateUserSite.do")
	public void updateUserSite(Site site,int userid) {
		biz.updateUserSite(site,userid);
	}
	
	//删除地址
	@RequestMapping(value="deleteUserSite.do")
	public void deleteUserSite(int siteid,int userid) {
		biz.deleteUserSite(siteid,userid);
	}
	
	//添加地址
	@ResponseBody
	@RequestMapping(value="saveUserSite.do")
	public void saveUserSite(HttpServletResponse response,HttpServletRequest request) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Site s=new Site();
		Long userid=new Long(request.getParameter("userid"));
		s.setUserid(userid);
		Long sphone=new Long(request.getParameter("sphone"));
		s.setSphone(sphone);
		s.setSsite(request.getParameter("ssite"));
		s.setSuser(request.getParameter("suser"));
		s.setScode(request.getParameter("scode"));
		if(request.getParameter("scode").equals("默认")) {
			biz.updateSiteScode0(userid);
		}
		biz.saveUserSite(s);
		
	}
	/*@ResponseBody
	@RequestMapping(value="saveUserSite1.do")
	public void saveUserSite1(HttpServletRequest request,HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		String suser=request.getParameter("suser");
		System.out.println(suser);
		//biz.saveUserSite(site);
	}*/
}